package com.ocean.array;

/**
 * https://leetcode.cn/problems/climbing-stairs/
 */
public class ClimbStairs2 {


    public static void main(String[] args) {
        System.out.println(new ClimbStairs2().climbStairs(2));
        System.out.println(new ClimbStairs2().climbStairs(3));
        System.out.println(new ClimbStairs2().climbStairs(4));
        System.out.println(new ClimbStairs2().climbStairs(5));
        System.out.println(new ClimbStairs2().climbStairs(6));
        System.out.println(new ClimbStairs2().climbStairs(7));
        System.out.println(new ClimbStairs2().climbStairs(8));
    }

    public int climbStairs(int n) {
        if (n == 0 || n == 1) {
            return 1;
        }
        if (n == 2) {
            return 2;
        }
        int result = 3;
        int first = 1;
        int second = 2;
        for (int i = 3; i < n; i++) {
            first = second;
            second = result;
            result = first + second;
        }
        return result;
    }


}
